import { Work } from "@/api/interface/work";
import { WorkState } from "@/redux/interface";
import * as types from "@/redux/mutation-types";
import produce from "immer";

export type WorkAction =
	| {
			type: "SET_WORK_LIST";
			payload: Work[];
	  }
	| {
			type: "SET_WORK_DETAIL";
			payload: Work;
	  };

const initState: WorkState = {
	workList: [],
	workDetail: {
		id: 0,
		work_title: "",
		work_image: "",
		work_des: "",
		work_url: "",
		createdAt: "",
		updatedAt: ""
	}
};

export default function WorkReducer(state: WorkState = initState, action: WorkAction) {
	return produce(state, draftState => {
		switch (action.type) {
			case types.SET_WORK_LIST:
				draftState.workList = action.payload;
				break;
			case types.SET_WORK_DETAIL:
				draftState.workDetail = action.payload;
				break;
			default:
				break;
		}
	});
}
